import Vue from 'vue';
import VueRouter from 'vue-router';

const login = () =>
    import( /* webpackChunkName: "login" */ '@/views/login');
// import login from '../views/login';
const main = () =>
    import( /* webpackChunkName: "main" */ '@/views/main');
// import main from '../views/main';
const me = () =>
    import( /* webpackChunkName:"me" */ '@/views/me');
// import me from '../views/me';

//工程管理
// import project from '@/views/modules/project';
const project = () =>
    import( /* webpackChunkName:"project" */ '@/views/modules/project');

//信息管理
// import index from '@/views/modules/index';
const index = () =>
    import( /* webpackChunkName:"index" */ '@/views/modules/index');
// import overview from '@/views/modules/index/overview';
const overview = () =>
    import( /* webpackChunkName:"overview" */ '@/views/modules/index/overview');
// import detail from '@/views/modules/index/detail';
const detail = () =>
    import( /* webpackChunkName:"detail" */ '@/views/modules/index/detail');
// import announce from '@/views/modules/index/detail/announce';
const announce = () =>
    import( /* webpackChunkName:"announce" */ '@/views/modules/index/detail/announce');
// import filecenter from '@/views/modules/index/detail/filecenter';
const filecenter = () =>
    import( /* webpackChunkName:"filecenter" */ '@/views/modules/index/detail/filecenter');
// import emergency from '@/views/modules/index/detail/emergency';
const emergency = () =>
    import( /* webpackChunkName:"emergency" */ '@/views/modules/index/detail/emergency');
// import organization from '@/views/modules/index/detail/organization';
const organization = () =>
    import( /* webpackChunkName:"organization" */ '@/views/modules/index/detail/organization');
// import sketch from '@/views/modules/index/detail/sketch';
const sketch = () =>
    import( /* webpackChunkName:"sketch" */ '@/views/modules/index/detail/sketch');
// import mytasks from '@/views/modules/index/detail/mytasks';
const mytasks = () =>
    import( /* webpackChunkName:"mytasks" */ '@/views/modules/index/detail/mytasks');
// import nodeprogress from '@/views/modules/index/detail/nodeprogress';
const nodeprogress = () =>
    import( /* webpackChunkName:"nodeprogress" */ '@/views/modules/index/detail/nodeprogress');

//质量控制
// import quality from '@/views/modules/quality';
const quality = () =>
    import( /* webpackChunkName:"quality" */ '@/views/modules/quality');
// import investoutline from '@/views/modules/quality/investoutline';
const investoutline = () =>
    import( /* webpackChunkName:"investoutline" */ '@/views/modules/quality/investoutline');
// import designfile from '@/views/modules/quality/designfile';
const designfile = () =>
    import( /* webpackChunkName:"designfile" */ '@/views/modules/quality/designfile');
// import fwquality from '@/views/modules/quality/fwquality';
const fwquality = () =>
    import( /* webpackChunkName:"fwquality" */ '@/views/modules/quality/fwquality');
// import resultsreview from '@/views/modules/quality/resultsreview';
const resultsreview = () =>
    import( /* webpackChunkName:"resultsreview" */ '@/views/modules/quality/resultsreview');
// import finishconfirm from '@/views/modules/quality/finishconfirm';
const finishconfirm = () =>
    import( /* webpackChunkName:"finishconfirm" */ '@/views/modules/quality/finishconfirm');

const fieldcondition = () =>
    import( /* webpackChunkName:"fieldcondition" */ '@/views/modules/quality/fieldcondition');

//计划控制
// import plan from '@/views/modules/plan';
const plan = () =>
    import( /* webpackChunkName:"plan" */
        '@/views/modules/plan');
// import progress from '@/views/modules/plan/progress';
const progress = () =>
    import( /* webpackChunkName:"progress" */ '@/views/modules/plan/progress');
// import fwprogress from '@/views/modules/plan/fwprogress';
const fwprogress = () =>
    import( /* webpackChunkName:"fwprogress" */ '@/views/modules/plan/fwprogress');
// import supervisionrecord from '@/views/modules/plan/supervisionrecord';
const supervisionrecord = () =>
    import( /* webpackChunkName:"supervisionrecord" */ '@/views/modules/plan/supervisionrecord');
// import changerecord from '@/views/modules/plan/changerecord';
const changerecord = () =>
    import( /* webpackChunkName:"changerecord" */ '@/views/modules/plan/changerecord');

//安全控制
// import safety from '@/views/modules/safety';
const safety = () =>
    import( /* webpackChunkName:"safety" */ '@/views/modules/safety');
// import rules from '@/views/modules/safety/rules';
const rules = () =>
    import( /* webpackChunkName:"rules" */ '@/views/modules/safety/rules');
// import clarifyrecords from '@/views/modules/safety/clarifyrecords';
const clarifyrecords = () =>
    import( /* webpackChunkName:"clarifyrecords" */ '@/views/modules/safety/clarifyrecords');
// import securitycheck from '@/views/modules/safety/securitycheck';
const securitycheck = () =>
    import( /* webpackChunkName:"securitycheck" */ '@/views/modules/safety/securitycheck');

//合同管理
// import contract from '@/views/modules/contract';
const contract = () =>
    import( /* webpackChunkName:"contract" */ '@/views/modules/contract');
// import workloadchange from '@/views/modules/contract/workloadchange';
const workloadchange = () =>
    import( /* webpackChunkName:"workloadchange" */ '@/views/modules/contract/workloadchange');
// import performance from '@/views/modules/contract/performance';
const performance = () =>
    import( /* webpackChunkName:"performance" */ '@/views/modules/contract/performance');
// import application from '@/views/modules/contract/application';
const application = () =>
    import( /* webpackChunkName:"application" */ '@/views/modules/contract/application');

//技术服务
// import technical from '@/views/modules/technical';
const technical = () =>
    import( /* webpackChunkName:"technical" */ '@/views/modules/technical');
// import accepinspection from '@/views/modules/technical/accepinspection';
const accepinspection = () =>
    import( /* webpackChunkName:"accepinspection" */ '@/views/modules/technical/accepinspection');
// import constrcooperation from '@/views/modules/technical/constrcooperation';
const constrcooperation = () =>
    import( /* webpackChunkName:"constrcooperation" */ '@/views/modules/technical/constrcooperation');
// import fdinspection from '@/views/modules/technical/fdinspection';
const fdinspection = () =>
    import( /* webpackChunkName:"fdinspection" */ '@/views/modules/technical/fdinspection');



//3D展示
const Tddisplay = () =>
    import('@/views/modules/3ddisplay');
const Threeddisplay = () =>
    import('@/views/modules/3ddisplay/3ddisplay');


    
//施工监控
const cctv = () =>
import('@/views/modules/cctv');
const cctvWindow = () =>
import('@/views/modules/cctv/cctvWindow');

Vue.use(VueRouter);

const routes = [{
    path: '/',
    name: 'login',
    redirect: '/login'
}, {
    path: '/login',
    name: 'login',
    component: login
}, {
    path: '/main',
    name: 'main',
    component: main,
    children: [{
        path: '/project',
        component: project,
        name: 'project'
    }, {
        path: '',
        component: index,
        name: 'index',
        children: [{
            path: '',
            component: overview,
            name: 'index-overview'
        },
        {
            path: 'index_detail',
            component: detail,
            name: 'index-detail',
            children: [{
                path: '',
                component: announce,
                name: 'index-detail-annouce'
            }, {
                path: 'mytasks',
                component: mytasks,
                name: 'index-detail-mytasks'
            }, {
                path: 'filecenter',
                component: filecenter,
                name: 'index-detail-filecenter'
            }, {
                path: 'emergency',
                component: emergency,
                name: 'index-detail-emergency'
            }, {
                path: 'organization',
                component: organization,
                name: 'index-detail-organization'
            }, {
                path: 'sketch',
                component: sketch,
                name: 'index-detail-sketch'
            }, {
                path: 'nodeprogress',
                component: nodeprogress,
                name: 'index-detail-nodeprogress'
            }]
        }
        ]
    }, {
        path: '/plan',
        component: plan,
        name: 'plan',
        children: [{
            path: '',
            component: progress,
            name: 'plan-progress'
        }, {
            path: 'fwprogress',
            component: fwprogress,
            name: 'plan-fwprogress'
        }, {
            path: 'supervisionrecord',
            component: supervisionrecord,
            name: 'plan-supervisionrecord'
        }, {
            path: 'changerecord',
            component: changerecord,
            name: 'plan-changerecord'
        }]
    }, {
        path: '/quality',
        component: quality,
        name: 'quality',
        children: [{
            path: '',
            component: investoutline,
            name: 'quality-investoutline',
        }, {
            path: 'designfile',
            component: designfile,
            name: 'quality-designfile',
        }, {
            path: 'fwquality',
            component: fwquality,
            name: 'quality-fwquality',
        }, {
            path: 'resultsreview',
            component: resultsreview,
            name: 'quality-resultsreview'
        }, {
            path: 'finishconfirm',
            component: finishconfirm,
            name: 'quality-finishconfirm'
        }, {
            path: 'fieldcondition',
            component: fieldcondition,
            name: 'quality-fieldcondition'
        }]
    }, {
        path: '/safety',
        component: safety,
        name: 'safety',
        children: [{
            path: '',
            component: rules,
            name: 'safety-rules',
        }, {
            path: 'clarifyrecords',
            component: clarifyrecords,
            name: 'safety-clarifyrecords',
        }, {
            path: 'securitycheck',
            component: securitycheck,
            name: 'safety-securitycheck'
        }]
    }, {
        path: '/contract',
        component: contract,
        name: 'contract',
        children: [{
            path: '',
            component: workloadchange,
            name: 'contract-workloadchange',
        }, {
            path: 'performance',
            component: performance,
            name: 'contract-performance',
        }, {
            path: 'application',
            component: application,
            name: 'contract-application'
        }]
    }, {
        path: '/technical',
        component: technical,
        name: 'technical',
        children: [{
            path: 'accepinspection',
            component: accepinspection,
            name: 'technical-accepinspection',
        }, {
            path: 'constrcooperation',
            component: constrcooperation,
            name: 'technical-constrcooperation',
        }, {
            path: '',
            component: fdinspection,
            name: 'technical-fdinspection'
        }]
    }, {
        path: '/3ddisplay',
        component: Tddisplay,
        name: '3ddisplay',
        children: [{
            path: '',
            component: Threeddisplay,
            name: '3ddisplay-3ddisplay',
        }]
    }, {
        path: '/cctv',
        component: cctv,
        name: 'cctv',
        children: [{
            path: '',
            component: cctvWindow,
            name: 'cctv-cctvWindow',
        }]
    }]
}, {
    path: '/me',
    name: 'me',
    component: me
}];

const router = new VueRouter({
    routes
});

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
    //to 将要访问的路径
    //from 从哪个路径而来
    //next 放行
    if (to.path === '/login') return next();

    //获取token
    const tokenstr = window.sessionStorage.getItem('token');
    if (!tokenstr) return next('/login');

    // let t = new Date();
    // to.query.t = t.getTime();
    next();
});

export default router;